package com.woniuxy.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wu
 * @date 2024/01/09 15:49:57
 */
public class OrderCodeUtils {
    public static String createOrderCode(Date date) {

        //生成格式化日期为"yymmdd"
        DateFormat format = new SimpleDateFormat("yyMMdd");
        if(null == date){
            date = new Date();
        }
        StringBuffer buffer = new StringBuffer();
        buffer.append(format.format(date));
        String code = buffer.toString();

        //随机生成四位数
        String timeMillis = System.currentTimeMillis() + "";
        String randomNum = timeMillis.substring(timeMillis.length() - 4);

        //生成订单编号
        String orderCode = code + randomNum;

        return orderCode;
    }
}
